package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.rare;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;


public class FadeSkill extends BaseSkill {

    public FadeSkill(int level) {
        super(level);
    }

    public FadeSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public FadeSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return String.format("凋谢技能，凋零状态下会快速恢复生命。");
    }

    public SkillRarity getSkillRarity() {
        return SkillRarity.Rare;
    }

    public boolean canUseAbility(MobEntity mobEntity) {
        return (mobEntity.getTarget() != null && getSkilltime() < mobEntity.world.getTime());
    }

    @Override
    public boolean passiveApply(MobEntity mobEntity) {
        if (mobEntity.hasStatusEffect(StatusEffects.WITHER)) {
            if (canUseAbility(mobEntity)) {
                setSkilltime(mobEntity.world.getTime() + getCooldown());
                mobEntity.heal(getSkillLevel());
            }
        }
        return true;
    }

    @Override
    public boolean onDamaged(LivingEntity attacker, MobEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        return !source.getName().equals("wither");
    }
}
